{{- $menusPositions := dict "right" "ml-auto" "left" "mr-auto" "center" "ml-auto mr-auto" -}}
{{- $baseURL := $.Site.BaseURL -}}
<nav class="navbar fixed-top navbar-expand-xl">
  <div class="container{{ if default false .Site.Params.fullWidth }}-fluid{{ end }}">
    <a class="navbar-brand{{ if .IsHome }} active{{ end }}" href="{{ absLangURL "" }}">
      <img class="logo" alt="Logo" src="{{ absURL (default "images/logo.webp" .Site.Params.logo) }}" loading="lazy">
      {{- with .Site.Params.brand -}}
      {{ . }}
      {{- end -}}
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav mr-2 mb-2 mb-lg-0">
        {{- partial "header/search-bar" . -}}
      </ul>
      {{- $menusPosition := default "right" .Site.Params.menusPosition  -}}
      <ul class="navbar-nav mb-2 mb-lg-0 mr-2 {{ index $menusPositions $menusPosition }}">
        {{- $currentPage := . -}}
        {{- range .Site.Menus.main -}}
        {{- $url := absLangURL .URL -}}
        {{- $active := or (eq $currentPage.Permalink (absLangURL .URL)) ($currentPage.IsMenuCurrent "main" .) -}}
        {{- if .HasChildren -}}
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle{{ if $currentPage.HasMenuCurrent "main" . }} active{{ end }}" id="navbarDropdown-{{ .Identifier }}" role="button" data-toggle="dropdown" aria-expanded="false">
            {{ .Pre }} {{- .Name -}} {{ .Post }}
          </a>
          <ul class="dropdown-menu" aria-labelledby="navbarDropdown-{{ .Identifier }}">
            {{- range .Children -}}
            {{- $childURL := absLangURL .URL -}}
            <li>
              <a class="dropdown-item{{ if or (eq $currentPage.Permalink (absLangURL .URL)) ($currentPage.IsMenuCurrent "main" .) }} active{{ end }}"
                href="{{ $childURL }}"{{ if not (hasPrefix $childURL $baseURL) }} target="_blank"{{ end }}>
                {{ .Pre }} {{- .Name -}} {{ .Post }}
              </a>
            </li>
            {{- end -}}
          </ul>
        </li>
        {{- else -}}
        <li class="nav-item">
          <a class="nav-link{{ if $active }} active{{ end }}" href="{{ $url }}"{{ if not (hasPrefix $url $baseURL) }} target="_blank"{{ end }}>
            {{ .Pre }} {{- .Name -}} {{ .Post }}
          </a>
        </li>
        {{- end -}}
        {{- end -}}
      </ul>
      <ul class="navbar-nav d-flex flex-row mb-2 mb-lg-0">
        {{- partial "header/language-switcher" . -}}
        {{- partial "header/palette-switcher" . -}}
        {{- partial "header/font-size-switcher" . -}}
        {{- partial "header/mode-switcher" . -}}
      </ul>
    </div>
  </div>
</nav>
